#ifndef adcmana_H
#define adcmana_H 1

#include <TGFrame.h>
#include <TGNumberEntry.h>
#include <TGButtonGroup.h>
#include <TGColorSelect.h>
#include <TGColorDialog.h>
#include <TGLabel.h>
#include <TCanvas.h>
//#include <TH2.h>
#include <THStack.h>
#include "TGMenu.h"
#include <TGFileDialog.h>
#include <TGStatusBar.h>
#include <TGCanvas.h>

#include "toptions.h"

#define MXLN 30
#define MXNUM 60

class TGWindow;
class TGMainFrame;
class TRootEmbeddedCanvas;

enum MENU_COM {
  M_READINIT,
  M_SAVEINIT,
  M_READROOT,
  M_SAVEROOT,
  M_FILE_BROWSE,
  M_FILE_NEWCANVAS,
  //M_FILE_OPEN,
  //M_FILE_SAVE,
  M_FILE_EXIT,
  M_PARAM,
  M_DEMON,
  M_SYNC,
  M_MKMON,
  M_MAKAN,
  M_HELP,
  M_TEST,
  M_SI,
  M_SIMAX,
  M_1_6,
  M_7_12,
  M_13_18,
  M_19_24,
  M_25_30,
  M_27_32,
  M_T1_6,
  M_T7_12,
  M_T13_18,
  M_T19_24,
  M_T25_30,
  M_T27_32,
#ifdef ROMASH
  M_TOF0_5,
  M_TOF6_11,
  M_TOF12_17,
  M_TOF18_23,
#endif
  M_CHANNELS
};

class NumDlg {

private:
   TGTransientFrame     *fMain;
   TGLabel              *fLabel[MXLN];
   TGNumberEntry        *fNum[MXNUM];
   TGHorizontalFrame    *fHor[MXLN];
   TGStatusBar          *fStatusBar;
   /*
   TGVerticalFrame      *fFrame1;
   TGHorizontalFrame    *fHor[MXLN];
   TGLayoutHints        *fLay1;
   TGLayoutHints        *fLay2;
   TGLayoutHints        *fLay3;
   TGLabel              *fLabel[MXLN];
   TGNumberEntry        *fNum[MXNUM];
   TGButton             *fSetButton;
  */
public:
   NumDlg(const TGWindow *p, const TGWindow *main, const char* txt[], 
	  double val[], int nn);
   virtual ~NumDlg();

   //void DoNum();
   void CloseWindow();
   void DoOK();

   int nNum;

  ClassDef(NumDlg, 0)
};

class EntryDlg {

private:
  //TGMainFrame          *fMain;
   TGTransientFrame     *fMain;
   TGCompositeFrame *fContainer;
   TGCanvas             *fCanvas;
   //   TGVerticalFrame      *fFrame1;
   TGHorizontalFrame    *fHor[MXLN];
   TGLayoutHints        *fLay1;
   TGLayoutHints        *fLay2;
   TGLayoutHints        *fLay3;
   TGLabel              *fLabel[MXLN];
   TGNumberEntry        *fNum[MXNUM];
   TGButton             *fSetButton;

   int nLine,nNum;

   void *r_entries[MXNUM];

public:
   EntryDlg(const TGWindow *p, const TGWindow *main, const char* title);
   virtual ~EntryDlg();

   void AddLine3(int, void*, void*, const char*, const char*, const char*, 
		 TGNumberFormat::EStyle, TGNumberFormat::EAttribute, 
		 int min=0, int max=0);
   // slots
   void DoNum3();
   void CloseWindow();
   //void SetLimits();
   //void DoOK();

  ClassDef(EntryDlg, 0)
};

class ChanDlg {

private:
   TGTransientFrame     *fMain;
   TGHorizontalFrame    *fFr1;
   TGVerticalFrame      *fFr2[2];
   TGHorizontalFrame    *fFr3;

   TGHorizontalFrame    *fHor[MAX_CH+1];
   //TGGroupFrame         *fHor[MAX_CH];
   TGLayoutHints        *fLay1,*fLay2,*fLay3,*fLay4;

   TGLabel              *fLabel[2];
   TGLabel              *fLab2[MAX_CH+1+MAX_P];
   TGRadioButton        *fR[MAX_R*(MAX_CH+1)];
   TGTextEntry          *fName[MAX_CH+1];
   TGColorSelect        *fColor[MAX_CH+1+MAX_P];
   //TGButton             *fSetButton;

public:
   ChanDlg(const TGWindow *p, const TGWindow *main, const char* title);
   virtual ~ChanDlg();

   void AddColumn(int);
   void AddLine(int, TGVerticalFrame*);
   void FillLine(int, TGHorizontalFrame*);
   void FillLast(int, TGHorizontalFrame*);
   void DoRadio();
   void DoSetName();
   void DoColor();
   void CloseWindow();
   void DoOK();


   ClassDef(ChanDlg, 0)
};

class MyMainFrame : public TGMainFrame {
  //RQ_OBJECT("MyMainFrame")
private:
  TGMainFrame          *fMain;
  TRootEmbeddedCanvas  *fEcanvas;
  TCanvas              *fcanvas;
  TCanvas              *fAna;
  TGNumberEntry        *n_events;
  TGMenuBar            *fMenuBar;     // main menu bar
  TGPopupMenu          *fMenuFile;    // "File" popup menu entry
  TGPopupMenu          *fMenuOptions;    
  TGPopupMenu          *fMenuHist;    
  TGPopupMenu          *fMenuAna;    
  TGPopupMenu          *fMenuHelp;    // "Help" popup menu entry
  TLegend              *fLeg[6];
  TLegend              *fLeg1ev;
  //THStack              *fHS[6];
  //TH2F                 *fHist[6];
  //TGraph               *fGr[6];


  bool                   bRun;

public:
  MyMainFrame(const TGWindow *p,UInt_t w,UInt_t h);
  virtual ~MyMainFrame();

  TGStatusBar          *fBar;

  void DoOpen();
  void DoRWinit(EFileDialogMode);
  void DoReadRoot();
  void DoReset();
  void DoClear();
  void InitCanvas(int);
  void DoDraw2();
  void DoDraw();
  void DrawSubPad(int);
  void Draw_SI();
  void Draw_SI_MAX();
  void Draw_NAI(int);
  void Draw_TNAI(int);
#ifdef ROMASH
  void Draw_MTOF(int);
#endif
  void DoCheckGcut();
  void DoCheckOsc();
  void DoCheckLeg();
  void DoCheckLogY();
  void DoCheckTime();
  void DoSave();
  void DoGcut(int);
  void DoExit();
  void DoStop();
  void DoAllevents();
  void DoFindBeam();
  void DoChkPoint();
  void Do1event();
  void DoNevents();

  void DoSync();
  void DoInitMON();
  void DoReadMakan();
  void MakeMonitor();

  void UpdateStatus();

  void DoSetNum();
  void HandleMenu(MENU_COM);
  //void HandleHelp();

  void exec3event(Int_t, Int_t, Int_t, TObject *);

  NumDlg               *fNumD;
  EntryDlg             *fPar;
  ChanDlg              *fChan;

  TGCanvas             *fTst;

  int nPads;

  ClassDef(MyMainFrame, 0)
};

enum ChannelDef {
  ch_gam,
  ch_ng,
  ch_nim,
  ch_off
};

#include <TGListTree.h>
#include <TSystemDirectory.h>


#endif
